package com.lkf.simplewebcontainer.http.impl;

import com.lkf.simplewebcontainer.http.Request;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.QueryStringDecoder;

import java.util.List;
import java.util.Map;

/**
 * 对request规范的简单实现
 * 利用netty提供的HttpRequest实现request
 * 利用netty提供的QueryStringDecoder解码request内容
 */
public class SimpleRequest implements Request {

    private HttpRequest request;

    public SimpleRequest(HttpRequest request) {
        this.request = request;
    }

    @Override
    public String getUri() {
        return new QueryStringDecoder(request.uri()).uri();
    }

    @Override
    public String getPath() {
        return new QueryStringDecoder(request.uri()).path();
    }

    @Override
    public String getRequestMethod() {
        return request.method().name();
    }

    @Override
    public Map<String, List<String>> parameters() {
        return new QueryStringDecoder(request.uri()).parameters();
    }
}
